From 64ed69c56fe79aae9940d909494c708e01b266c9 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 1 Aug 2020 22:01:52 -0400 Subject: [PATCH] label: Be more selective when selecting on focus-in We don't want to select on focus-in when the focus comes from a child. The case where this does harm is when you activate copy or paste actions from the context menu. We close the menu before triggering the action, and if that causes the text in the label to be selected, unexpected things happen, since the action applies to the current selection. This is the equivalent of cd9f5733b3e354301f2 for GtkLabel. --- gtk/gtklabel.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 453f6023c7..c39699fed1 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -3710,10 +3710,13 @@ gtk_label_grab_focus (GtkWidget *widget) { GtkLabel *self = GTK_LABEL (widget); gboolean select_on_focus; + GtkWidget *prev_focus; if (self->select_info == NULL) return FALSE; + prev_focus = gtk_root_get_focus (gtk_widget_get_root (widget)); + if (!GTK_WIDGET_CLASS (gtk_label_parent_class)->grab_focus (widget)) return FALSE; @@ -3724,12 +3727,14 @@ gtk_label_grab_focus (GtkWidget *widget) &select_on_focus, NULL); - if (select_on_focus && !self->in_click) + if (select_on_focus && !self->in_click && + !(prev_focus && gtk_widget_is_ancestor (prev_focus, widget))) gtk_label_select_region (self, 0, -1); } else { - if (self->select_info->links && !self->in_click) + if (self->select_info->links && !self->in_click && + !(prev_focus && gtk_widget_is_ancestor (prev_focus, widget))) { guint i; -- 2.30.2